package com.crm.jdy.controller.usermanager;

import com.crm.jdy.common.pojo.PermissionCatalogue;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.usermanager.PermissionCatalogueService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
*
* <p>说明： 权限对应的目录API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年4月6日
*
*/
@Api(tags = "permissionCatalogue", description = "权限对应的目录")
@RestController
@RequestMapping("/permissionCatalogue")
public class PermissionCatalogueController{

    @Reference(version = "${service.version}", check = false)
    PermissionCatalogueService permissionCatalogueService;

    @RateLimit()
    @ApiOperation("权限对应的目录")
    @PostMapping("/seletePermissionCatalogue")
    public ResultVo seletePermissionCatalogue(@RequestBody PermissionCatalogue callAplanInfoDto){
        List<PermissionCatalogue> list = permissionCatalogueService.seletePermissionCatalogue(callAplanInfoDto);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新权限对应的目录")
    @PostMapping("/updatePermissionCatalogue")
    public ResultVo updatePermissionCatalogue(@ApiParam(value = "roleInfo", required = true)
                                   @Validated @RequestBody PermissionCatalogue roleInfo){
        boolean index = permissionCatalogueService.updatePermissionCatalogue(roleInfo);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("多个添加权限对应的目录")
    @PostMapping("/addAllPermissionCatalogue")
    public ResultVo addAllPermissionCatalogue(@ApiParam(name = "roleInfo", required = false)
                                @Validated @RequestBody List<PermissionCatalogue> catalogueList){
        boolean list  = permissionCatalogueService.addUpatePermissionCatalogue(catalogueList);
        if(list){
            return ResultVo.success("添加成功");
        }
        return ResultVo.failed("添加失败，数据已存在");
    }

    @RateLimit()
    @ApiOperation("添加权限对应的目录")
    @PostMapping("/addPermissionCatalogue")
    public ResultVo addPermissionCatalogue(@ApiParam(name = "roleInfo", required = false)
                                @Validated @RequestBody PermissionCatalogue roleInfo){
        boolean list  = permissionCatalogueService.addPermissionCatalogue(roleInfo);
        if(list){
            return ResultVo.success("添加成功");
        }
        return ResultVo.failed("添加失败，数据已存在");
    }

    @RateLimit()
    @ApiOperation("删除权限对应的目录")
    @DeleteMapping("deleteRoleInfo/{peCa}")
    public ResultVo deletePermissionCatalogue(@NotNull @ApiParam(name = "peCa", value = "peCa", required = true) @PathVariable String peCa){
        boolean b = permissionCatalogueService.removePermissionCatalogue(peCa);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }




}